package com.crimax.lanproj.controller;
import java.io.IOException;
import java.util.List;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.crimax.lanproj.properties.LoanProperties;
import com.crimax.lanproj.properties.LoanPropertiesHolder;
import com.crimax.lanproj.properties.NameHolder;
public class ForwardProd implements Controller {
  protected final Log logger = LogFactory.getLog(getClass());
  
  ResourceBundle credits = ResourceBundle.getBundle("lan");

  
  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    logger.info("Return View");
    
    LoanPropertiesHolder holder = LoanPropertiesHolder.getSingletonObject();
    
    List<LoanProperties> loanProperties = holder.getLoanProperties();
    List<LoanProperties> bigLoanProperties = holder.getbigLoanSortSupplierByLoanSize();
    
    String product = request.getParameter("product");
    String url = "";
    
    for (LoanProperties loanProperty : loanProperties) {
    	String name = loanProperty.getFriendlyName();
		if(name.equalsIgnoreCase(product)){
			url = loanProperty.getURL();
			return new ModelAndView("redirect:http://"+url);
		}
	}
    
    for (LoanProperties loanProperty : bigLoanProperties) {
    	String name = loanProperty.getFriendlyName();
		if(name.equalsIgnoreCase(product)){
			url = loanProperty.getURL();
			return new ModelAndView("redirect:http://"+url);
		}
	}
    System.out.println(url);
    return new ModelAndView("redirect:http://"+url);
  }
} 